<?php
namespace app\model;

use app\common\model\_Base;

class ArticleType extends _Base
{

    /**
     * 保存数据
     * @param  obj $data 数据
     * @param  integer  $id 数据编号
     * @return bool       
     */
    public static function doSave($data,$id = '')
    {   
        $type = $id?ArticleType::get($id):new ArticleType;
        !empty($data['name']) && $type['name'] = $data['name'];
        isset($data['pid']) && strlen($data['pid']) > 0 && $type->pid = $data['pid'];
        isset($data['sort']) && strlen($data['sort']) > 0 && $type->sort = $data['sort'];
        $type->save();
        return;
    }

    /**
     * 删除数据
     * @param  integer $id 数据编号
     * @return bool       
     */
    public static function doDelete($id)
    {
        $role = ArticleType::destroy($id);
        return false;
    }


    /**
     * 获取数据
     * @param  array    $cond  条件
     * @param  string   $alias 条件表别名
     * @param  integer  $page  页码
     * @param  integer  $limit 每页条数
     * @return array
     */
    public static function doList($cond = [], $alias = false, $order = 'sort')
    {   
        $list = ArticleType::where($cond)->order($order)->select();
        return ['list' => $list];
    }
}